import request from '@/utils/request'

// 1. 登录
export const userLoginService = ({ username, password }: Api.Login.LoginParams) => {
  return request.post<Api.Login.LoginResponse>('/user/login/', {
    username,
    password
  })
}

// 2. 注册
export const userRegisterService = ({ username, password, rePassword }: Api.Login.FormModel) => {
  return request.post<Api.Register.RegisterResponse>('/user/register/', {
    username,
    password,
    rePassword
  })
}

// 3. 获取用户信息
export const userGetUserInfoService = (username: Api.User.GetUserInfoParams) => {
  return request.get<Api.User.UserInfoResponse>('/user/getUserInfo/', {
    params: { username }
  })
}

// 4. 获取用户列表
export const userGetUserListService = (params?: Api.User.GetUserListParams) => {
  return request.get<Api.User.UserListResponse>('/user/getUserList/', {
    params
  })
}

// 5. 删除用户
export const userDeleteUserService = (ids: number[]) => {
  return request.delete<Api.User.UserListResponse>(`/user/deleteUser/`, {
    data: { ids }
  })
}

// 6. 获取用户详情
export const userGetUserDetailService = (id: number) => {
  return request.get<Api.User.UserDetailResponse>(`/user/${id}/getUserDetail/`)
}

// 7. 添加用户
export const userAddUserService = (data: FormData) => {
  return request.post<Api.User.AddUserResponse>('/user/addUser/', data)
}

// 8. 更新用户
export const userUpdateUserService = (data: FormData) => {
  return request.put<Api.User.AddUserResponse>('/user/updateUser/', data)
}
